/*
 * 描          述:  <描述>
 * 修  改   人:  PengQingyang
 * 修改时间:  2022年5月18日
 * <修改描述:>
 */
package com.tx.component.sendsms.configuration;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import com.tx.component.communication.starter.CommunicationContextProperties;
import com.tx.component.sendsms.context.SendSMSEngineFactory;
import com.tx.component.sendsms.context.SendSMSWithTemplateHandlerComposite;
import com.tx.component.sendsms.plugin.SendSMSWithTemplateHandler;
import com.tx.component.sendsms.service.SmsTemplateService;

/**
 * 发送短信引擎Configuration<br/>
 * <功能详细描述>
 * 
 * @author  PengQingyang
 * @version  [版本号, 2022年5月18日]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
@Import({ SendSMSContextPersisterConfiguration.class })
@Configuration
public class SendSMSContextConfiguration {
    
    protected CommunicationContextProperties properties;
    
    /** <默认构造函数> */
    public SendSMSContextConfiguration(
            CommunicationContextProperties properties) {
        super();
        this.properties = properties;
    }
    
    /**
     * 使用短信发送短信处理器<br/>
     * <功能详细描述>
     * @return [参数说明]
     * 
     * @return SendSMSWithTemplateHandlerComposite [返回类型说明]
     * @exception throws [异常类型] [异常说明]
     * @see [类、类#方法、类#成员]
     */
    @Bean("cmu.sendSMSWithTemplateHandlerComposite")
    public SendSMSWithTemplateHandlerComposite sendSMSWithTemplateHandlerComposite(
            ObjectProvider<SendSMSWithTemplateHandler> sendSMSWithTemplateHandlerProvider) {
        List<SendSMSWithTemplateHandler> handlers = sendSMSWithTemplateHandlerProvider
                .orderedStream()
                .collect(Collectors.toList());
        SendSMSWithTemplateHandlerComposite composite = new SendSMSWithTemplateHandlerComposite();
        composite.setHandlers(handlers);
        return composite;
    }
    
    /**
     * 发送短信引擎<br/>
     * <功能详细描述>
     * @return [参数说明]
     * 
     * @return SendSMSEngineFactory [返回类型说明]
     * @exception throws [异常类型] [异常说明]
     * @see [类、类#方法、类#成员]
     */
    @Bean("cmu.sendSMSEngine")
    public SendSMSEngineFactory sendSMSEngine(
            SendSMSWithTemplateHandlerComposite composite,
            SmsTemplateService smsTemplateService) {
        SendSMSEngineFactory factory = new SendSMSEngineFactory();
        factory.setComposite(composite);
        factory.setSmsTemplateService(smsTemplateService);
        return factory;
    }
}
